home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / pc / windows / qtw_201 / setup / samples / qtwsaver / qtwsaver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-19  |  6.2 KB  |  210 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // QTWSAVER.C   - QuickTime for Windows
  5. //
  6. //                Version 1.0
  7. //
  8. //                (c) Copyright 1988-1994 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. #include <windows.h>
  14. #include <commdlg.h>
  15. #include <scrnsave.h>
  16. #include <qtw.h>
  17. #include <direct.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h> 
  21. #include "fileexts.rh"
  22.  
  23. static MovieFile mfMovie;
  24. static Movie mMovie;
  25. static MovieController mcController;
  26.  
  27. char szAppName[40];
  28. HINSTANCE _cdecl hMainInstance;
  29. HWND _cdecl hMainWindow;
  30. char _cdecl szName[TITLEBARNAMELEN];
  31. char _cdecl szIsPassword[22];
  32. char _cdecl szIniFile[MAXFILELEN];
  33. char _cdecl szScreenSaver[22];
  34. char _cdecl szPassword[16];
  35. char _cdecl szDifferentPW[BUFFLEN];
  36. char _cdecl szChangePW[30];
  37. char _cdecl szBadOldPW[BUFFLEN];
  38. char _cdecl szHelpFile[MAXFILELEN];
  39. char _cdecl szNoHelpMemory[BUFFLEN];
  40. UINT _cdecl MyHelpMessage;
  41. HOOKPROC _cdecl fpMessageFilter;
  42.  
  43. VOID NEAR MySelectAMovie (VOID);
  44.  
  45.  
  46. // RegisterDialogClasses
  47. // ---------------------------------------------------------------------
  48. BOOL RegisterDialogClasses (HINSTANCE hInst)
  49. {
  50.     return TRUE;
  51. }
  52.  
  53.  
  54. // ScreenSaverProc
  55. // ---------------------------------------------------------------------
  56. LRESULT WINAPI ScreenSaverProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  57. {
  58.     RECT rcMovie, rcClient;
  59.     char szSection[_MAX_PATH];
  60.     char szProfile[_MAX_PATH];
  61.     char szMovie[_MAX_PATH];
  62.  
  63.     // Drive the movie controller
  64.  
  65.     MCIsPlayerMessage (mcController, hWnd, message, wParam, lParam);
  66.  
  67.     // Act on message from Windows
  68.  
  69.     switch (message)
  70.  
  71.     {
  72.         // Creating screen saver
  73.  
  74.         case WM_CREATE:
  75.  
  76.             // Initialize QTW
  77.  
  78.             if ((QTInitialize (NULL) != QTI_OK) || (EnterMovies () != noErr)) {
  79.                 DestroyWindow (hWnd);
  80.                 return 0;
  81.             }
  82.  
  83.             // Get movie name
  84.  
  85.             for (;;) {
  86.                 LoadString (hMainInstance, idsAppName, szSection, sizeof (szSection));
  87.                 LoadString (hMainInstance, idsIniFile, szProfile, sizeof (szProfile));
  88.                 GetPrivateProfileString (szSection, "Movie", "", szMovie, sizeof (szMovie), szProfile);
  89.                 if (szMovie[0] != 0) break;
  90.                 MySelectAMovie ();
  91.             }
  92.  
  93.             // Open the movie
  94.  
  95.             if (OpenMovieFile (szMovie, &mfMovie, OF_READ) != noErr) {
  96.                 DestroyWindow (hWnd);
  97.                 return 0;
  98.             }
  99.             NewMovieFromFile (&mMovie, mfMovie, NULL, NULL, 0, NULL);
  100.             CloseMovieFile (mfMovie);
  101.  
  102.             // Instantiate the controller
  103.  
  104.             GetMovieBox (mMovie, &rcMovie);
  105.             GetClientRect (GetDesktopWindow (), &rcClient);
  106.             OffsetRect(&rcMovie, -rcMovie.left, -rcMovie.top);
  107.             rcMovie.right *= 2, rcMovie.bottom *= 2;
  108.             OffsetRect(&rcMovie, (rcClient.right - rcMovie.right) / 2,
  109.                 (rcClient.bottom - rcMovie.bottom) / 2);
  110.             mcController = NewMovieController (mMovie, &rcMovie,
  111.                 mcTopLeftMovie + mcScaleMovieToFit + mcNotVisible, hWnd);
  112.  
  113.             // Action!
  114.  
  115.             SetMovieActive (mMovie, TRUE);
  116.             InvalidateRect (hWnd, &rcMovie, FALSE);
  117.             MCDoAction (mcController, mcActionSetVolume, (LPVOID) MAKESFIXED (0, 64));
  118.             MCDoAction (mcController, mcActionSetFlags, (LPVOID) mcFlagsUseWindowPalette);
  119.             MCDoAction (mcController, mcActionSetLooping, (LPVOID) TRUE);
  120.             PrerollMovie (mMovie, 0, MAKELFIXED (1, 0));
  121.             MCDoAction (mcController, mcActionPlay, (LPVOID) MAKELFIXED (1, 0));
  122.             break;
  123.  
  124.         // Destroying the screen saver
  125.  
  126.         case WM_DESTROY:
  127.             DisposeMovieController (mcController);
  128.             DisposeMovie (mMovie);
  129.             ExitMovies ();
  130.             QTTerminate ();
  131.             break;
  132.  
  133.         // Paint It Black
  134.  
  135.         case WM_ERASEBKGND:
  136.             GetClientRect (hWnd, &rcMovie);
  137.             FillRect ((HDC) wParam, &rcMovie, (HBRUSH) GetStockObject (BLACK_BRUSH));
  138.             return 0;
  139.  
  140.     }
  141.  
  142.     // Return to Windows
  143.  
  144.     return DefScreenSaverProc (hWnd, message, wParam, lParam);
  145. }
  146.  
  147.  
  148. // ScreenSaverConfigureDialog
  149. // ---------------------------------------------------------------------
  150. BOOL WINAPI ScreenSaverConfigureDialog (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  151. {
  152.     switch (message) {
  153.         case WM_INITDIALOG:
  154.             MySelectAMovie ();
  155.             EndDialog (hDlg, TRUE);
  156.             return TRUE;
  157.     }
  158.     return FALSE;
  159. }
  160.  
  161.  
  162. // MySelectAMovie
  163. // ---------------------------------------------------------------------
  164. VOID NEAR MySelectAMovie (VOID)
  165. {
  166.     char szDir[_MAX_DIR];
  167.     char szFileTitle[_MAX_PATH];
  168.     char szMovie[_MAX_PATH];
  169.     char szSection[_MAX_PATH];
  170.     char szFilter[_MAX_PATH];
  171.     char szProfile[_MAX_PATH];
  172.     char* p;
  173.     OPENFILENAME ofn;
  174.  
  175.     // Where was the old movie?
  176.  
  177.     LoadString (hMainInstance, idsAppName, szSection, sizeof (szSection));
  178.     LoadString (hMainInstance, idsIniFile, szProfile, sizeof (szProfile));
  179.     GetPrivateProfileString (szSection, "Movie", "", szDir, sizeof (szMovie), szProfile);
  180.     if (strlen (szDir) > 0) {
  181.         p = strrchr (szDir, '\\');
  182.         *p = 0;
  183.     }
  184.     else _getcwd (szDir, sizeof (szDir));
  185.  
  186.     // Select a movie
  187.  
  188.     szMovie[0] = '\0';
  189.     memset (&ofn, 0, sizeof(OPENFILENAME));
  190.     ofn.lStructSize = sizeof(OPENFILENAME);
  191.     ofn.hwndOwner = 0;
  192.     ofn.lpstrFilter = CommonGetFileFilter (hMainInstance, (WORD) COMMON_MOVIES_FILEEXT, szFilter, sizeof szFilter);
  193.     ofn.nFilterIndex = 1;
  194.     ofn.lpstrFile = szMovie;
  195.     ofn.nMaxFile = sizeof(szMovie);
  196.     ofn.lpstrFileTitle = szFileTitle;
  197.     ofn.nMaxFileTitle = sizeof(szFileTitle);
  198.     ofn.lpstrInitialDir = szDir;
  199.     ofn.lpstrTitle = "Select a Movie";
  200.     ofn.Flags = OFN_HIDEREADONLY;
  201.     if (GetOpenFileName (&ofn) != 0) {
  202.         WritePrivateProfileString (szSection, "Movie", szMovie, szProfile);
  203.     }
  204.  
  205.     // Return to caller
  206.  
  207.     return;
  208.  
  209. }
  210.